﻿using System.Xml;

namespace Jayden.Dll.Sc2.Descriptions.Protoss
{
	public class WarpActionDescription : BuildActionDescription
	{
		private long m_Cooldown = 0;

		protected WarpActionDescription(EntityDescription entity, EntityDescription build, string id, long cooldown)
			: base(entity, build, id)
		{
			m_Cooldown = cooldown;
		}
		public WarpActionDescription(EntityDescription entity, XmlNode node, string format = "{0}WarpIn{1}", string nameFormat = "{0} warp in {1}")
			: base(entity, node, format, nameFormat)
		{
			m_Cooldown = long.Parse(node.Attributes["cooldown"].Value);
		}

		public override void Execute(GameState state)
		{
			RemoveResources(state);
			state.Add(Entity, 0, -1, 0);
			state.Add(Build, 1, 0, 1);
			BaseExecute(state);
			DelayedActionDescription warpIn = new DelayedActionDescription(this, 5 + state.Time, delegate(GameState innerState)
			{
				innerState.Add(Build, -1, 1, 0);
			});
			state.Add(warpIn);
			DelayedActionDescription endCooldown = new DelayedActionDescription(this, m_Cooldown + state.Time, delegate(GameState innerState)
			{
				innerState.Add(Entity, 0, 1, 0);
			}, Id + "CooldownFinished");
			state.Add(endCooldown);
		}
	}
}
